package com.itheima.socketdemo8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10002);

        while (true) {
            Socket accept = ss.accept();
            //网络中的流，从客户端读取数据的
            BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
            //本地的IO流，把数据写道本地中，实现永久化存储
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("E:\\java\\javaTest\\socketmodule\\ServerDir\\copy.jpg"));

            int b;
            while ((b = bis.read()) != -1) {
                bos.write(b);
            }
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
            bw.write("上传成功");
            bw.newLine();
            bw.flush();
            bos.close();
            accept.close();
        }
        //
        // ss.close();
    }
}
